package com.app.micaihu.view.army.dialog

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.app.base.BaseBottomSheetDialogFragment
import com.app.micaihu.R
import com.app.micaihu.bean.news.ShareBean
import com.app.micaihu.configure.Config
import com.app.micaihu.configure.UmEventId
import com.app.micaihu.utils.MobclickAgentUtils
import com.app.micaihu.view.utils.ShareUtils
import com.blankj.utilcode.util.ToastUtils
import com.umeng.socialize.UMShareAPI
import com.umeng.socialize.bean.SHARE_MEDIA
import kotlinx.android.synthetic.main.army_member_share_dialog.*


/**
 * 成员列表分享
 */
class ArmyMemberShareDialog : BaseBottomSheetDialogFragment() {

    override fun getLayoutId() = R.layout.army_member_share_dialog

    override fun getBundle(bundle: Bundle) {
        shareBean = bundle.getSerializable(Config.Extra.share) as ShareBean
    }

    var shareBean: ShareBean? = null
    override fun setData() {

    }

    override fun addListeners() {
        tvQQ.setOnClickListener {
            dismiss()
            shareBean?.let {
                ShareUtils.instance.shareWx(it, SHARE_MEDIA.QQ)
            }
        }
        tvWx.setOnClickListener {
            dismiss()
            shareBean?.let {
                ShareUtils.instance.shareWx(it, SHARE_MEDIA.WEIXIN)
            }
        }
        tvSina.setOnClickListener {
            dismiss()
            shareBean?.let {
                ShareUtils.instance.shareWx(it, SHARE_MEDIA.SINA)
            }
        }
        tvCopy.setOnClickListener {
            shareBean?.let { share ->
                val copy = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?
                copy?.let {
                    MobclickAgentUtils.event(UmEventId.articleshare_click, UmEventId.shareCopy)
                    it.setPrimaryClip(ClipData.newPlainText(null, share.shareUrl))
                    ToastUtils.showShort("复制成功")
                    dismiss()
                }
            }

        }
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        UMShareAPI.get(activity).onActivityResult(requestCode, resultCode, data)
    }

}